<?php

/**
 * 我的推荐
 */

namespace app\sale\common;

class UserHasCommon extends \app\member\common\MemberCommon {


    protected function index() {
        $this->pageInfo['name'] = '我的推荐';
        $this->setMeta('我的推荐');
        $this->setCrumb([
            [
                'name' => '我的推荐',
                'url' => url()
            ]
        ]);

        $type = request('get', 'type', 0, 'intval');

        switch ($type) {
            case 0:
            default:
                $max = 1;
                break;
            case 1:
                $max = 2;
                break;
            case 2:
                $max = 3;
                break;
        }

        $userList = target('sale/SaleUser')->levelList($this->userInfo['user_id'], 3);

        $total = [];
        foreach ($userList as $vo) {
            $total[] = count($vo);
        }

        $count = count($userList);
        $pageData = $this->pageData($count, 10, ['type' => $type]);


        if($userList[$max]) {
            $list = array_slice($userList[$max], $pageData['limit'][0], $pageData['limit'][1]);
        }else {
            $list = [];
        }

        $this->assign('pageList', $list);
        $this->assign('page', $pageData['html']);
        $this->assign('type', $type);
        $this->assign('total', $total);
        $this->memberDisplay();
    }

}